package com.datastructure.test.dayoftemperature;

public class DayOfTemperatures {

    public static void main(String[] args) {
        DayOfTemperatures dayOfTemperatures = new DayOfTemperatures();
        int[] dailyTemperatures = {1,1,1,1};
        int[] temperatures = dayOfTemperatures.temperatures(dailyTemperatures);
        System.out.println(temperatures);
    }

    public int[] temperatures (int[] dailyTemperatures) {
        // write code here
        if(dailyTemperatures==null){
            return null;
        }
        int length = dailyTemperatures.length;
        int[] result = new int[length];
        if(length==1){
            result[0]=0;
            return result;
        }
        int temp;
        for (int i = 0; i < length; i++) {
            int j = i+1;
            temp=1;
            while (j<length){
                if(dailyTemperatures[j]>dailyTemperatures[i]){
                    break;
                }
                temp++;
                j++;
            }
            if(i<length-2&&j==length){
                result[i] = 0;
            } else {
                result[i]=temp;
            }
        }
        result[length-1]=0;
        if(dailyTemperatures[length-2]<dailyTemperatures[length-1]){
            result[length-2]=1;
        } else {
            result[length-2]=0;
        }
        return result;
    }
}
